/*
 * main.c
 *
 *  Created on: Jul 27, 2013
 *      Author: lxzhu
 */
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
void onDraw();
void onDrawBitmapText(char* val);
void onDrawStrokeText(char* val);

int main(int argc, char** argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutCreateWindow("Hello OpenGL");
	glutDisplayFunc(onDraw);
	glutMainLoop();
	return 0;
}

void onDraw() {
	glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_LINE_LOOP);
	glVertex2f(0.4, 0.5);
	glVertex2f(0.2, 0.7);
	glVertex2f(-0.2, 0.3);
	glVertex2f(0, 0);
	glEnd();
	glRasterPos2f(-1.0, -1.0);

	onDrawStrokeText("Hello World!");
	glutSwapBuffers();
}

void onDrawBitmapText(char* val) {
	int ch;
	int idx = 0;
	void *font = GLUT_BITMAP_TIMES_ROMAN_10;

	while ((ch = val[idx++])) {
		//int width=glutBitmapWidth(font,ch);
		glutBitmapCharacter(font, ch);
	}
}
void onDrawStrokeText(char* val) {
	int ch;
	int idx = 0;
	void *font = GLUT_STROKE_MONO_ROMAN;
	float ratio = 1.0 / glutStrokeWidth(font, 'M');
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glTranslatef(-1.0, -0.9, 0);
	glScalef(ratio/20, ratio/20, 1);

	while ((ch = val[idx++])) {
		glutStrokeCharacter(font, ch);
	}
	glPopMatrix();
}
